package com.yq.homework.day30.udp1;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketTimeoutException;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/30 20:11
 */
public class ReceiveInfo implements Runnable{
    DatagramSocket socket;

    public ReceiveInfo(DatagramSocket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //只接收数据
        while (true){
            DatagramPacket receivePacket = NetUtils.getReceivePacket();
            try {
                socket.receive(receivePacket);
                String parse = NetUtils.parse(receivePacket);
                System.out.println(receivePacket.getSocketAddress()+"发来了："+parse);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }
}
